/**
 *	实验五
 *
 *	写一程序统计纯文本文件的大写字母、小写字母个数，
 *	并将所有小写字母转换为大写字母，输出到out.txt
 */
import java.io.*;
class  T5E05
{
	public static void main(String[] args) 
	{
		int capitalNum = 0;
		int lowerNum = 0;
		int lineNum = 1;
		int wordNum = 1;
		try
		{
			BufferedReader fin  = new BufferedReader(new FileReader("love.txt"));
			BufferedWriter fout = new BufferedWriter(new FileWriter("statistics.txt"));
			BufferedWriter out = new BufferedWriter(new FileWriter("out.txt"));
			int buffer = 0;
			while ((buffer = fin.read())!= -1)
			{
				int temp = buffer;

				System.out.print(buffer);
				if (buffer >= 'a' && buffer <= 'z')
				{
					lowerNum++;
					temp = temp - 32;
				}
				else if (buffer >= 'A' && buffer <= 'Z')
				{
					capitalNum++;
				}
				else if (buffer == '\r')
				{
					lineNum++;
				}
				else if (buffer == ' ')
				{
					wordNum++;
				}
				out.write(temp);
			}
			String statis = "总共有：" +  lineNum + "行，" + wordNum + "单词"
				+"。大写字母有："+capitalNum + "个，" 
				+"小写字母有："+ lowerNum + "个.";
			fout.write(statis);
			fout.flush();
			fout.close();
			out.flush();
			out.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
}